package com.dcy.web.controller;

import com.dcy.common.base.controller.DcyBaseController;
import com.dcy.common.model.LoginAccount;
import com.dcy.common.model.R;
import com.dcy.common.utils.satoken.StpAdminUtil;
import com.dcy.system.service.UserInfoService;
import com.dcy.system.vo.in.LoginInVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dcy
 * @Date: 2019/3/22 10:17
 * @Description:
 */
@RequiredArgsConstructor
@RestController
@ApiSupport(order = 1)
@Api(value = "LoginController", tags = {"登录接口"})
@Slf4j
public class LoginController extends DcyBaseController {

    private final UserInfoService userInfoService;

    @ApiOperation(value = "用户登录")
    @ApiOperationSupport(order = 1, author = "dcy")
    @PostMapping("/login")
    public R<String> login(@Validated @ApiParam @RequestBody LoginInVO loginInVO) {
        return success(userInfoService.login(loginInVO));
    }

    @ApiOperation(value = "获取用户信息")
    @ApiOperationSupport(order = 5, author = "dcy")
    @GetMapping("/getUserInfo")
    public R<LoginAccount> getUserInfo() {
        return success(userInfoService.getUserInfo());
    }

    @ApiOperation(value = "用户退出")
    @ApiOperationSupport(order = 10, author = "dcy")
    @PostMapping("/logout")
    public R<String> logout() {
        StpAdminUtil.logout();
        return success("退出成功");
    }
}
